package com.zwj.design.test.creating.factory;

import com.zwj.design.test.creating.factory.factory.CircleFactory;
import com.zwj.design.test.creating.factory.factory.RectangleFactory;
import com.zwj.design.test.creating.factory.factory.ShapeFactory;
import com.zwj.design.test.creating.factory.factory.TriangleFactory;
import com.zwj.design.test.creating.factory.shape.Shape;

/**
 * 工厂方法模式练习
 * @author 张文接
 * @version 1.0
 * @createTime 2024/3/11 15:29
 */
public class Demo {
    /**
     * 假设有一个图形处理系统，需要支持绘制不同类型的形状，如圆形、矩形和三角形。请设计一个简单工厂模式来实现此需求，包括以下要求：
     * <p>
     * 定义一个抽象的形状接口（Shape）以及它的具体实现类（Circle、Rectangle、Triangle）。
     * 创建一个ShapeFactory类，它提供一个静态方法createShape(String type)，根据传入的字符串type动态创建相应的形状对象。
     */
    public static void main(String[] args) {
        ShapeFactory shapeFactory = getShapeFactory("Rectangle");
        Shape shape = shapeFactory.createShape();
        shape.outputInfo();
    }

    public static ShapeFactory getShapeFactory(String type) {
        ShapeFactory shapeFactory;
        if ("Circle".equals(type)) {
            shapeFactory = new CircleFactory();
        } else if ("Rectangle".equals(type)) {
            shapeFactory = new RectangleFactory();
        } else {
            shapeFactory = new TriangleFactory();
        }
        return shapeFactory;
    }
}
